package me.hys.action.system;

import java.util.Map;

import me.hys.base.AjaxResult;
import me.hys.base.BaseAction;
import me.hys.entity.system.ConfigEntity;
import me.hys.service.system.IConfigManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Author: @author HYS . <br>
 * Date: 2015-9-16 下午9:57:05 . <br>
 * Function: 简介
 */
@Controller
@RequestMapping("/profile")
public class ProfileAction extends BaseAction {
	@Autowired
	private IConfigManager configManager;

	/**
	 * @Fields : 标志
	 */
	private String flag;

	public ProfileAction() {
		flag = getClass().getSimpleName();
		setFlag(flag);
	}

	/**
	 * @Title : edit
	 * @Description : 修改页面
	 */
	@RequestMapping("/edit/{id}")
	public ModelAndView edit(@PathVariable String id) {
		Map<String, Object> data = getMap();
		data.put("entity", configManager.findById(id));
		return new ModelAndView("/system/profile_form", data);
	}

	/**
	 * @Title : index
	 * @Description : 公司简介
	 */
	@RequestMapping("/index")
	public ModelAndView index() {
		Map<String, Object> data = getMap();
		data.put("data", configManager.findByFlags(new String[] { "company",
				"service" }));
		return new ModelAndView("/system/profile", data);
	}

	/**
	 * @Title : save
	 * @Description : 保存配置
	 */
	@RequestMapping("/save")
	@ResponseBody
	public AjaxResult save(@ModelAttribute ConfigEntity entity,
			@RequestHeader(value = "referer") String url) {
		configManager.saveOrUpdate(entity);
		AjaxResult ajaxResult = new AjaxResult();
		ajaxResult.setMsg(url);
		return ajaxResult;
	}

}
